package com.anli02.RabbitMQConfig;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


@Configuration
public class RabbitMQConfig {
    //声明交换机
    @Bean
    public DirectExchange directExchage()
    {
        return ExchangeBuilder.directExchange("music").build();
    }
    //创建队列
    @Bean
    public Queue directQueue()
    {

        Map<String, Object> args = new HashMap<>();
        args.put("x-queue-mode", "lazy");  // 设置队列为懒人模式
        return new Queue("direct.music", true, false, false, args);  // 持久化，非独占，非自动删除
    }

    @Bean
    public  Binding bindingQueue(Queue directQueue ,DirectExchange  directExchage  )
    {


        return BindingBuilder.bind(directQueue).to(directExchage).with("musicKey");
    }

}